package com.lxl.demo01.controller;

import com.lxl.demo01.controller.utils.R;
import com.lxl.demo01.domain.DoAlert;
import com.lxl.demo01.service.IDoAlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/doalerts")
public class DoAlertController {
    @Autowired
    private IDoAlertService iDoAlertService;

    // 页面层-查询所有数据
    @GetMapping
    public R getAll() {
        // 调用业务层来执行
        return new R(true, iDoAlertService.list());
    }

    // 页面层-查询单个数据
    @GetMapping("{id}")
    public R getById(@PathVariable Long id) {
        // 调用业务层来执行
        return new R(true, iDoAlertService.getById(id)); // 只要查询了，都成功
    }

    // 页面层-添加一条数据
    @PostMapping
    public R save(@RequestBody DoAlert doAlert) {
        // 调用业务层来执行
        R r = new R(iDoAlertService.save(doAlert));
        return r; // 返回的是R对象，统一风格
    }

    // 页面层-修改一条数据
    @PutMapping
    public R update(@RequestBody DoAlert doAlert) {
        // 调用业务层来执行
        return new R(iDoAlertService.updateById(doAlert));
    }

    // 页面层-删除一条数据(通过id)
    @DeleteMapping("{id}")
    public R delete(@PathVariable Long id) {
        // 调用业务层来执行
        return new R(iDoAlertService.removeById(id));
    }

    // 页面层-分页查询
    @GetMapping("{currentPage}/{pageSize}")
    public R getPage(@PathVariable int currentPage, @PathVariable int pageSize) {
        // 调用业务层中自定义的方法来执行
        return new R(true, iDoAlertService.getPage(currentPage, pageSize));
    }

    // 按天查询
    @GetMapping("/day")
    public R getDay() {
        return new R(true, iDoAlertService.selectDay());
    }

    @GetMapping("/week")
    public R getWeek() {
        return new R(true, iDoAlertService.selectWeek());
    }

    @GetMapping("/month")
    public R getMonth() {
        return new R(true, iDoAlertService.selectMonth());
    }

    // 分页查询统计
    @GetMapping("/daypage/{monitor_type}/{currentPage}/{pageSize}")
    public R getDayPage(@PathVariable Integer monitor_type, @PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return new R(true, iDoAlertService.getDayPage(monitor_type, currentPage, pageSize));
    }

    @GetMapping("/monthpage/{monitor_type}/{currentPage}/{pageSize}")
    public R getMonthPage(@PathVariable Integer monitor_type, @PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return new R(true, iDoAlertService.getMonthPage(monitor_type, currentPage, pageSize));
    }

    @GetMapping("/weekpage/{monitor_type}/{currentPage}/{pageSize}")
    public R getWeekPage(@PathVariable Integer monitor_type, @PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return new R(true, iDoAlertService.getWeekPage(monitor_type, currentPage, pageSize));
    }
}
